package com.leetcode.August;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: 148. 排序链表
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-27 16:42
 */
public class LC148排序链表 {
    public ListNode sortList(ListNode head) {
        List<Integer> list =new ArrayList<>();
        while (head!=null){
            list.add(head.val);
            head=head.next;
        }
        Collections.sort(list);
        ListNode dum=new ListNode(0);
        ListNode tail=dum;
        for (Integer i : list) {
            tail.next=new ListNode(i);
            tail=tail.next;
        }
        return dum.next;
    }
}
